package com.app.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

public class BookQ {
	
	public BookQ() {
		CustomerPhonenumber = CustomerFirstName = CustomerLastName = CustomerSex = CustomerClass = CustomerShop 
				= CustomerFood = CustomerTime = CustomerAlet = CustomerTable = CustomerNumber = CustomerStartTime 
				= CustomerEndTime = CustomerQ = CustomerStatus = CustomerIsMessage = CustomerWaittime = "";
	 }	
    public BookQ(
            String OID,
            String UsrOpt,
            String IsActive,
            String IsDeleted,
            String CustomerPhonenumber,
            String CustomerFirstName,
            String CustomerLastName,
            String CustomerSex,
            String CustomerClass,
            String CustomerShop,
            String CustomerFood,
            String CustomerTime,
            String CustomerAlet,
            String CustomerTable,
            String CustomerNumber,
            String CustomerStartTime,
            String CustomerEndTime,
            String CustomerQ,
            String CustomerStatus,
            String CustomerIsMessage,
            String CustomerWaittime
            
            
            )
    
   {
        this.OID 					= OID;
        this.UsrOpt 				= UsrOpt;
        this.IsActive 				= IsActive;
        this.IsDeleted 				= IsDeleted;
        this.CustomerPhonenumber 	= CustomerPhonenumber;
        this.CustomerFirstName 		= CustomerFirstName;
        this.CustomerLastName 		= CustomerLastName;
        this.CustomerSex 			= CustomerSex;
        this.CustomerClass 			= CustomerClass;
        this.CustomerShop 			= CustomerShop;
        this.CustomerFood 			= CustomerFood;
        this.CustomerTime 			= CustomerTime;
        this.CustomerAlet 			= CustomerAlet;
        this.CustomerTable 			= CustomerTable;
        this.CustomerNumber 		= CustomerNumber;
        this.CustomerStartTime 		= CustomerStartTime;
        this.CustomerEndTime 		= CustomerEndTime;
        this.CustomerQ 				= CustomerQ;
        this.CustomerStatus 		= CustomerStatus;
        this.CustomerIsMessage 		= CustomerIsMessage;
        this.CustomerWaittime 		= CustomerWaittime;
        
        

    }
    //-------------------- Variable -------------------------
    private String OID,
    		UsrOpt,
    		IsActive,
    		IsDeleted,
    		CustomerPhonenumber,
    		CustomerFirstName,
    		CustomerLastName,
    		CustomerSex,
    		CustomerClass,
    		CustomerShop,
    		CustomerFood,
    		CustomerTime,
    		CustomerAlet,
    		CustomerTable,
    		CustomerNumber,
    		CustomerStartTime,
    		CustomerEndTime,
    		CustomerQ,
    		CustomerStatus,
    		CustomerIsMessage,
    		CustomerWaittime;
    
   
	Connect_old con = new Connect_old(); 
    Connection conn = con.Connect();
    ResultSet rs = null;
    
 // -------------------- GET-SET -------------------------
    
    
 	public String getOID() {
 		return OID;
 	}
 	
 	public String getCustomerQ() {
 		return CustomerQ;
 	}
 	public void setCustomerQ(String customerQ) {
 		CustomerQ = customerQ;
 	}
 	public String getCustomerStatus() {
 		return CustomerStatus;
 	}
 	public void setCustomerStatus(String customerStatus) {
 		CustomerStatus = customerStatus;
 	}
 	public String getCustomerIsMessage() {
 		return CustomerIsMessage;
 	}
 	public void setCustomerIsMessage(String customerIsMessage) {
 		CustomerIsMessage = customerIsMessage;
 	}
 	public String getCustomerWaittime() {
 		return CustomerWaittime;
 	}
 	public void setCustomerWaittime(String customerWaittime) {
 		CustomerWaittime = customerWaittime;
 	}
 	public String getCustomerStartTime() {
 		return CustomerStartTime;
 	}
 	public void setCustomerStartTime(String customerStartTime) {
 		CustomerStartTime = customerStartTime;
 	}
 	public String getCustomerEndTime() {
 		return CustomerEndTime;
 	}
 	public void setCustomerEndTime(String customerEndTime) {
 		CustomerEndTime = customerEndTime;
 	}
 	public String getCustomerSex() {
 		return CustomerSex;
 	}
 	public void setCustomerSex(String customerSex) {
 		CustomerSex = customerSex;
 	}
 	public String getCustomerClass() {
 		return CustomerClass;
 	}
 	public void setCustomerClass(String customerClass) {
 		CustomerClass = customerClass;
 	}
 	public String getCustomerShop() {
 		return CustomerShop;
 	}
 	public void setCustomerShop(String customerShop) {
 		CustomerShop = customerShop;
 	}
 	public String getCustomerFood() {
 		return CustomerFood;
 	}
 	public void setCustomerFood(String customerFood) {
 		CustomerFood = customerFood;
 	}
 	public String getCustomerTime() {
 		return CustomerTime;
 	}
 	public void setCustomerTime(String customerTime) {
 		CustomerTime = customerTime;
 	}
 	public String getCustomerTable() {
 		return CustomerTable;
 	}
 	public void setCustomerTable(String customerTable) {
 		CustomerTable = customerTable;
 	}
 	public String getCustomerNumber() {
 		return CustomerNumber;
 	}
 	public void setCustomerNumber(String customerNumber) {
 		CustomerNumber = customerNumber;
 	}
 	public String getCustomerAlet() {
 		return CustomerAlet;
 	}
 	public void setCustomerAlet(String customerAlet) {
 		CustomerAlet = customerAlet;
 	}
 	
 	public void setOID(String oID) {
 		OID = oID;
 	}
 	public String getUsrOpt() {
 		return UsrOpt;
 	}
 	public void setUsrOpt(String usrOpt) {
 		UsrOpt = usrOpt;
 	}
 	public String getIsActive() {
 		return IsActive;
 	}
 	public void setIsActive(String isActive) {
 		IsActive = isActive;
 	}
 	public String getIsDeleted() {
 		return IsDeleted;
 	}
 	public void setIsDeleted(String isDeleted) {
 		IsDeleted = isDeleted;
 	}
 	public String getCustomerPhonenumber() {
 		return CustomerPhonenumber;
 	}
 	public void setCustomerPhonenumber(String customerPhonenumber) {
 		CustomerPhonenumber = customerPhonenumber;
 	}
 	public String getCustomerFirstName() {
 		return CustomerFirstName;
 	}
 	public void setCustomerFirstName(String customerFirstName) {
 		CustomerFirstName = customerFirstName;
 	}
 	public String getCustomerLastName() {
 		return CustomerLastName;
 	}
 	public void setCustomerLastName(String customerLastName) {
 		CustomerLastName = customerLastName;
 	}
 	
 	//-------------------- SQL ------------------------
     public ResultSet selectBookQ(String CustomernameSearch,String IsActive,String DateNow,String CustomerTable,String Status) throws Exception {
         String StrSql = "SELECT [OID],"
                 + "[LastModified],"
                 + "[ModifiedDate],"
                 + "[ModifiedTime],"
                 + "[ModifiedBy],"
                 + "[UserModified],"
                 + "[CreatDate],"
                 + "[CreatTime],"
                 + "[CreatedBy],"
                 + "[UserCreate],"
                 + "[IsActive],"
                 + "[IsDeleted],"
                 
                 + "[CustomerPhonenumber],"
                 + "[CustomerFirstName],"
                 + "[CustomerLastName],"
                 + "[CustomerSex],"
                 + "[CustomerClass],"
                 + "[CustomerShop],"
                 + "[CustomerFood],"
                 + "[CustomerTime],"
                 + "[CustomerAlet],"
                 + "[CustomerTable],"
                 + "[CustomerNumber],"
                 + "[CustomerStartTime],"
                 + "[CustomerEndTime],"
                 + "[CustomerQ],"
                 + "[CustomerStatus],"
                 + "[CustomerIsMessage],"
                 + "[CustomerWaittime] "
                 
   				+ "FROM [Project_NFC].[dbo].[udfBookQ]() "
   
                 + "WHERE [IsDeleted]='0' "; 

         if (!IsActive.equals("")) {
             StrSql += " AND [IsActive] = "+IsActive ;
         }
         
         if (!CustomernameSearch.equals("")) {
             StrSql += " AND [CustomerFirstName] LIKE '%" + CustomernameSearch + "%' OR [CustomerPhonenumber] LIKE '%" + CustomernameSearch + "%' " ;
         }
         
         if (!CustomerTable.equals("")) {
             StrSql += " AND [CustomerTable] LIKE '%" + CustomerTable + "%' " ;
         }
         
         if (!Status.equals("")) {
             StrSql += " AND [CustomerStatus] LIKE '%" + Status + "%' " ;
         }
         
         if (!DateNow.equals("")) {
             StrSql += " AND [OID]  LIKE '%" + DateNow + "%' " ;
         }
         
         StrSql += " ORDER BY CustomerTime ASC " ;
         
         //return sqlsel.getReSultSQL(StrSql);
         return con.selectData(StrSql);
     }

     public String OperationData(String OperationType) throws Exception {
         try {
         		conn = con.Connect();
                 java.sql.CallableStatement cstmt = conn.prepareCall("{call stpBookQManagement(?,?,?,?,? ,?,?,?,?,? ,?,?,?,?,? ,?,?,?,?,? ,?,?,? )}");
                 
                 cstmt.setString(1, OperationType);
                 cstmt.setString(2, getOID());
                 cstmt.setString(3, getUsrOpt());
                 cstmt.setString(4, getIsActive());
                 cstmt.setString(5, getIsDeleted());

                 cstmt.setString(6, getCustomerPhonenumber());
                 cstmt.setString(7, getCustomerFirstName());
                 cstmt.setString(8, getCustomerLastName());
                 cstmt.setString(9, getCustomerSex());
                 cstmt.setString(10, getCustomerClass());
                 cstmt.setString(11, getCustomerShop());
                 cstmt.setString(12, getCustomerFood());
                 cstmt.setString(13, getCustomerTime());
                 cstmt.setString(14, getCustomerAlet());
                 cstmt.setString(15, getCustomerTable());
                 cstmt.setString(16, getCustomerNumber());
                 cstmt.setString(17, getCustomerStartTime());
                 cstmt.setString(18, getCustomerEndTime());
                 cstmt.setString(19, getCustomerQ());
                 cstmt.setString(20, getCustomerStatus());
                 cstmt.setString(21, getCustomerIsMessage());
                 cstmt.setString(22, getCustomerWaittime());
                 
                 cstmt.registerOutParameter(23, Types.VARCHAR);
                 cstmt.execute();
                 return cstmt.getString(23);
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
             if (conn != null) {
                 conn.close();
             }
         }
         return null;
     }
    
    
}
